package com.cdtu.store.item.controller;

import com.cdtu.store.common.entity.SpecParamEntity;
import com.cdtu.store.common.utils.PageUtils;
import com.cdtu.store.common.utils.R;
import com.cdtu.store.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;




/**
 * 规格参数组下的参数名
 *
 * @author dongyuhao
 * @email a1059444570@qq.com
 * @date 2020-06-22 19:53:26
 */
@RestController
@RequestMapping("specparam")
public class SpecParamController {
    @Autowired
    private SpecParamService specParamService;
    /**
     * 查询SKU特有属性列表
     */
    @GetMapping("/list/sale/{cid}")
    public R SaleList(@PathVariable("cid")Long cid){
        List<SpecParamEntity> saleList =  specParamService.SaleList(cid);
        return R.ok().put("data",saleList);
    }
    /**
     * 查询通用属性列表
     */
    @GetMapping("/list/base/{cid}")
    public R BaseList(@PathVariable("cid")Long cid){
        List<SpecParamEntity> baseList =  specParamService.BaseList(cid);
        return R.ok().put("data",baseList);
    }


    /**
     * 列表
     */
    @GetMapping("/list/{cid}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("cid") Long cid){
        //PageUtils page = specParamService.queryPage(params);
        PageUtils page = specParamService.queryPage(params,cid);

        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpecParamEntity specParam = specParamService.getById(id);

        return R.ok().put("specParam", specParam);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SpecParamEntity specParam){
		specParamService.save(specParam);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody SpecParamEntity specParam){
		specParamService.updateById(specParam);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		specParamService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
